<?php
	namespace Qzn\Model;
	
	class FriendListHandler {
		private $m_db = null;
		
		public function __construct(Database $db) {
			$this->m_db = $db;
		}
		
		/**
		 * Gets an array of friends
		 * @return array $ml
		 */
		public function GetFriendList ($flPk) {
			$fl =  DatabaseQuery::SelectFriendList($flPk, $this->m_db);			
			
			return $fl;
		}
		
		/**
		 * Removes a friendship from db
		 * @param FriendListView $flw
		 */
		public function RemoveFriend(\Qzn\View\FriendListView $flw, \Qzn\View\LoginView $lw) {
			if ($flw->MyFriendList($lw)) {
				$user2Pk = $flw->GetRemoveFriend();
				
				if (isset($user2Pk)) {
					DatabaseQuery::RemoveFriendQuery($lw->GetUserPk(), $user2Pk, $this->m_db);
					DatabaseQuery::RemoveFriendQuery($user2Pk, $lw->GetUserPk(), $this->m_db);
				}
			}
		}

		/**
		 * Block a friend
		 * @param FriendListVIew $flw
		 */
		public function BlockFriend(\Qzn\View\FriendListView $flw, \Qzn\View\LoginView $lw) {
			if ($flw->MyFriendList($lw)) {
				$user2Pk = $flw->GetBlockFriend();
				
				if (isset($user2Pk)) {
					DatabaseQuery::BlockFriendQuery($lw->GetUserPk(), $user2Pk, $this->m_db);
					DatabaseQuery::BlockFriendQuery($user2Pk, $lw->GetUserPk(), $this->m_db);
				}
			}
		}
		
		/**
		 * Unblock a friend
		 * @param FriendListVIew $flw
		 */
		public function UnblockFriend(\Qzn\View\FriendListView $flw, \Qzn\View\LoginView $lw) {
			if ($flw->MyFriendList($lw)) {
				$user2Pk = $flw->GetUnblockFriend();
				
				if (isset($user2Pk)) {
					DatabaseQuery::UnblockFriendQuery($lw->GetUserPk(), $user2Pk, $this->m_db);
					DatabaseQuery::UnblockFriendQuery($user2Pk, $lw->GetUserPk(), $this->m_db);
				}
			}
		}
		
		/**
		 * Block a friend
		 * @param FriendListVIew $flw
		 */
		public function AcceptFriend(\Qzn\View\FriendListView $flw, \Qzn\View\LoginView $lw) {
			if ($flw->MyFriendList($lw)) {
				$user1Pk = $flw->GetAcceptFriend();
				
				if (isset($user1Pk)) {
					DatabaseQuery::AcceptFriendQuery($user1Pk, $lw->GetUserPk(), $this->m_db);
				}
			}
		}
	}
?>